package yutProject;

import java.util.Random;

import javax.swing.JFrame;

public class Main extends JFrame {

	private static Yut yut1 = new Yut();
	private static Yut yut2 = new Yut();
	private static Yut yut3 = new Yut();
	private static Yut yut4 = new Yut();

	private static int yutt1, yutt2, yutt3, yutt4;

	private static final int BACK_DO = -1;

	public static int minusRate = 0;
	public static final int trash = 99;

	public static final int initPoint = -10;

	private static final Painter painter = new Painter();

	public static boolean keep = false;
	public static int total[] = { 0, 0, 0, 0, 0, 0 };

	public static int inpoint_1[] = { trash, trash, trash, trash, trash, trash };
	public static int inpoint_1_etc[] = { trash, trash, trash, trash, trash,
			trash };

	public static int inpoint_2[] = { trash, trash, trash, trash, trash, trash };
	public static int inpoint_2_etc[] = { trash, trash, trash, trash, trash,
			trash };

	public static int inpoint_3[] = { trash, trash, trash, trash, trash, trash };
	public static int inpoint_3_etc[] = { trash, trash, trash, trash, trash,
			trash };

	public static int noStart = trash;

	public static int keep_Data[] = new int[10];

	public static int turn_main = 0;

	public static boolean more_chance = false;

	final static int turnpoint1 = 5;
	final static int turnpoint2 = 10;

	public static int size = 0;
	public static int user = 0;
	public static int resultyut;

	public static int endP1 = 0;
	public static int endP2 = 0;
	public static int endP1_1 = 0;
	public static int endP2_1 = 0;

	private final static int DO = 1;
	private final static int GE = 2;
	private final static int GEOL = 3;
	private final static int YUT = 4;
	private final static int MO = 5;

	/**
	 * 게임 메인 메소드
	 * 
	 * @param args
	 */

	public static void main(String[] args) {

		turn_main = painter.turn;
		resultyut = 0;
		if (painter.throw_push == 2) {
			switch (painter.maindevision) {
			// 윷 던지기
			case 1:

				yutt1 = yut1.ThrowYut();
				yutt2 = yut2.ThrowYut();
				yutt3 = yut3.ThrowYut();
				yutt4 = yut4.ThrowYut();

				size = ThrowyutRate();
				
				if (keep == true) {
					painter.keep_value(size);
				}

				painter.judge(yutt1, yutt2, yutt3, yutt4);

				System.out.println("가야할 거리 : " + size);
				System.out.println("throwcount: "+painter.throwcount);
				break;

			case 2:
				total[turn_main] += size;
				if(painter.bt_value != 0)
				{
					painter.keep_Array[painter.bt_value]=0;
					painter.array_count=0;
				}
				if(painter.keep_doing==true)
				{
					painter.k_Button_remove(size);
					painter.keep_doing=false;
					
				}

				if (total[turn_main] == -1) {
					noStart = 0;

				}

				if (total[turn_main] == turnpoint1) {
					inpoint_1[turn_main] = 0;

				}

				else if (inpoint_1[turn_main] == 0
						&& inpoint_1_etc[turn_main] == 0) {
					inpoint_1[turn_main] = 1;

				}

				else if (total[turn_main] == turnpoint2) {
					inpoint_2[turn_main] = 0;

				}

				else if (inpoint_2[turn_main] == 0
						&& inpoint_2_etc[turn_main] == 0) {
					inpoint_2[turn_main] = 1;

				}

				else if (inpoint_3[turn_main] == 0) {
					inpoint_3_etc[turn_main] = 0;
				}
				if (total[0] >= 21 && total[2] >= 21) {
					painter.win_P1.setBounds(300, 250, 150, 100);
				} else if (total[1] >= 21 && total[3] >= 21) {
					painter.win_P2.setBounds(300, 250, 150, 100);
				}

				break;

			}

		}
	}

	/**
	 * 확률에 따른 윷을 반환해줌. 윷은 종류에 따라 나올 확률이 각기 다르고 그 확률은 다음과 같다. 도 - 4/16 = 1/4 =
	 * 25% 개 - 6/16 = 3/8 = 37.5% 걸 - 4/16 = 1/4 = 25% 윷 - 1/16 = 1/16 = 6.25% 모
	 * - 1/16 = 1/16 = 6.25%
	 * 
	 * @return
	 */
	public static int ThrowyutRate() {

		resultyut = yutt1 + yutt2 + yutt3 + yutt4;

		minusRate = (int) (Math.random() * 4);

		switch (resultyut) {
		case 0:
			more_chance = true;
			keep = true;
			return YUT;

		case 3:

			if (minusRate != 0) {
				user = 0;
				return DO;
			}

			else if (minusRate == 0) {
				user = 1;
				return BACK_DO;
			}

		case 2:
			return GE;
		case 1:
			return GEOL;
		case 4:
			more_chance = true;
			keep = true;
			return MO;
		}

		return resultyut;

	}

}
